/**
* @file		Node.ixx
* @brief	代表一块地
*
*
* @version	1.0
* @author	lveyou
* @date		22-03-09
*
*/

export module Node;

import DND;

import DefVar;

export class Node
{
public:
	struct SL
	{
		Point _xy;
		natural _typeTerrain;//地形
	};

	struct TP
	{
		TP() :
			_uidArea{(size_t)-1}
		{}
		size_t _uidArea;//所属区域
	};

	struct UI
	{
		gcSprite _sprTerrain;
	};

	Node() {}

	Node(SL sl) :
		_sl(sl)
	{

	}

	void RefreshUI();

	void Render()
	{
		_ui._sprTerrain->Render();
	}

	const SL& GetSL() { return _sl; }

	SL& GetSlRef() { return _sl; }
	TP& GetTpRef() { return _tp; }

	void Save(StreamOutput& s)
	{
		s.Write(&_sl);
	}

	void Load(StreamInput& s, n32 version)
	{
		s.Read(&_sl._xy);
		s.Read(&_sl._typeTerrain);
	}

private:
	SL _sl;
	UI _ui;
	TP _tp;
};

//! 返回节点y 纬度 顶对齐
//export real GetNodeLongitude(zahlen y)
//{
//	return -y * 0.1 + DefVar::LL_NODE_ZERO[1] * 0.1;
//}

//! xy到LL
export Point Xy2Ll(const Point& xy)
{
	return { xy[0] + DefVar::LL_NODE_ZERO[0], -xy[1] + DefVar::LL_NODE_ZERO[1]};
}

//! LL到xy
export Point Ll2Xy(const Point& xy)
{
	//x' = x + a	<=>		x = x' - a
	//y' = -y + b	<=>		y = -y' + b
	return { xy[0] - DefVar::LL_NODE_ZERO[0], -xy[1] + DefVar::LL_NODE_ZERO[1] };
}

//! 返回节点面积
export real GetNodeAcreage(const Point& xy)
{
	real dx = DefVar::SIZE_NODE_REAL;

	//转为纬度
	real y0 = Xy2Ll(xy)[1] * DefVar::L_PER_NODE;
	real y1 = y0 - DefVar::L_PER_NODE;

	//转为弧度
	real b0 = abs(y0 * std::numbers::pi / 180.0);
	real b1 = abs(y1 * std::numbers::pi / 180.0);

	return dx * Numbers::EARTH_RADIUS * (abs(sin(b0) - sin(b1)));
}